package org.jeecg.modules.bigdatashow.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.bigdatashow.entity.Station;
import org.jeecg.modules.bigdatashow.service.IStationService;
import org.jeecg.modules.bigdatashow.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 工位表
 * @Author: jeecg-boot
 * @Date:   2022-04-05
 * @Version: V1.0
 */
@Api(tags="工位表")
@RestController
@RequestMapping("/station")
@Slf4j
public class StationController extends JeecgController<Station, IStationService> {
	@Autowired
	private org.jeecg.modules.bigdatashow.service.IStationService stationService;
	
	/**
	 * 查询所有
	 * @return
	 */
	@GetMapping(value = "/list",produces = "application/json; charset=utf-8")
	public CommonResult queryList() {
		List<Station> stationList = stationService.list();

		if (stationList != null){

			return new CommonResult(200,"查询成功",stationList);
		}else{
			return new CommonResult(404,"未查询到数据");
		}
	}


	/**
	 * 通过生产线id查询
	 * @return
	 */
	@GetMapping(value = "/selectByLineId",produces = "application/json; charset=utf-8")
	public CommonResult selectByLineId(String id) {
		List<Station> stationList = stationService.selectByLineId(id);

		if (stationList != null){

			return new CommonResult(200,"查询成功",stationList);
		}else{
			return new CommonResult(404,"未查询到数据");
		}
	}
	
	/**
	 *   添加
	 *
	 * @param station
	 * @return
	 */
	@AutoLog(value = "工位表-添加")
	@ApiOperation(value="工位表-添加", notes="工位表-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody org.jeecg.modules.bigdatashow.entity.Station station) {
		stationService.save(station);
		return Result.OK("添加成功！");
	}


	
	/**
	 *  编辑
	 *
	 * @param station
	 * @return
	 */
	@AutoLog(value = "工位表-编辑")
	@ApiOperation(value="工位表-编辑", notes="工位表-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody org.jeecg.modules.bigdatashow.entity.Station station) {
		stationService.updateById(station);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "工位表-通过id删除")
	@ApiOperation(value="工位表-通过id删除", notes="工位表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		stationService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "工位表-批量删除")
	@ApiOperation(value="工位表-批量删除", notes="工位表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stationService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "工位表-通过id查询")
	@ApiOperation(value="工位表-通过id查询", notes="工位表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		org.jeecg.modules.bigdatashow.entity.Station station = stationService.getById(id);
		if(station==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(station);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param station
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, org.jeecg.modules.bigdatashow.entity.Station station) {
        return super.exportXls(request, station, org.jeecg.modules.bigdatashow.entity.Station.class, "工位表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, org.jeecg.modules.bigdatashow.entity.Station.class);
    }

}
